In mathematics, a square number, sometimes also called a perfect square, is an integer that is the square of an integer; in other words, it is the product of some integer with itself. So, for example, 9 is a square number, since it can be written as 3 × 3. Square numbers are non-negative. Another way of saying that a (non-negative) number is a square number, is that its square root is again an integer. For example, √9 = 3, so 9 is a square number.
A positive integer that has no perfect square divisors except 1 is called square-free.
The usual notation for the formula for the square of a number n is not the product n × n, but the equivalent exponentiation n2, usually pronounced as "n squared". For a non-negative integer n, the nth square number is n2, with 02 = 0 being the zeroth square. The concept of square can be extended to some other number systems. If rational numbers are included, then a square is the ratio of two square integers, and, conversely, the ratio of two square integers is a square (e.g., 4/9 = (2/3)2).
Starting with 1, there are square numbers up to and including m.
Contents |
The squares (sequence A000290 in OEIS) below 502 are:
The difference between any perfect square and its predecessor is given by the following identity,
Also, it is possible to count up square numbers by adding together the last square, the last square's root, and the current root. Mathematically expressed,
The number m is a square number if and only if one can arrange m points in a square:
m = 12 = 1 | |
m = 22 = 4 | |
m = 32 = 9 | |
m = 42 = 16 | |
m = 52 = 25 |
The expression for the nth square number is n2. This is also equal to the sum of the first n odd numbers as can be seen in the above pictures, where a square results from the previous one by adding an odd number of points (shown in cyan). The formula follows:
So for example, 52 = 25 = 1 + 3 + 5 + 7 + 9.
The nth square number can be calculated from the previous two by doubling the (n − 1)-th square, subtracting the (n − 2)-th square number, and adding 2, because n2 = 2(n − 1)2 − (n − 2)2 + 2. For example, 2 × 52 − 42 + 2 = 2 × 25 − 16 + 2 = 50 − 16 + 2 = 36 = 62.
A square number is also the sum of two consecutive triangular numbers. The sum of two consecutive square numbers is a centered square number. Every odd square is also a centered octagonal number.
Another property of a square number is that the number its divisor is odd, while other number have even number of divisors. Lagrange's four-square theorem states that any positive integer can be written as the sum of 4 or fewer perfect squares. Three squares are not sufficient for numbers of the form 4k(8m + 7). A positive integer can be represented as a sum of two squares precisely if its prime factorization contains no odd powers of primes of the form 4k + 3. This is generalized by Waring's problem.
A square number can only end with digits 00,1,4,6,9, or 25 in base 10, as follows:
In base 16, a square number can only end with 0,1,4 or 9 and
- in case 0, only 0,1,4,9 can precede it,
- in case 4, only even numbers can precede it.
There is a simple Boolean formula to perform this test on any number n using only the least significant byte:
if (n and 7) = 1 or (n and 31) = 4 or (n and 127) = 16 or (n and 191) = 0 then print n "is probably square" else print n "is definitely not square".
In general, if a prime divides a number then also the square of that prime must divide the number, if it fails to divide it second time, the number is definitely not square. Every prime must divide the number even times. At certain point it is faster to run square root on the number than to test it for all primes up to 4th root of the number.
Squarity testing can be used as alternative way in factorization of large numbers. Instead of testing for divisibility, just test for squarity: for given m and some number k, if k²- m is square of any number n then k - n divides m. For example 100² - 9991 is square of 3, consequently 100 - 3 divides 9991. This test is deterministic for odd divisors in range from k - n to k + n where k covers some range of natural numbers k ≥ √m.
A square number cannot be a perfect number.
Squares of even numbers are even, since (2n)2 = 4n2.
Squares of odd numbers are odd, since (2n + 1)2 = 4(n2 + n) + 1.
It follows that square roots of even square numbers are even, and square roots of odd square numbers are odd.